<!DOCTYPE html>
<!-- saved from url=(0044)http://www.html5rocks.com/en/tutorials/cors/ -->
<html lang="en" dir="ltr" itemscope="" itemtype="http://schema.org/Article" class="js flexbox canvas canvastext webgl no-touch geolocation postmessage websqldatabase indexeddb hashchange history draganddrop websockets rgba hsla multiplebgs backgroundsize borderimage borderradius boxshadow textshadow opacity cssanimations csscolumns cssgradients cssreflections csstransforms csstransforms3d csstransitions fontface generatedcontent video audio localstorage sessionstorage webworkers applicationcache svg inlinesvg smil svgclippaths adownload webaudio no-battery blobconstructor contenteditable cors csscalc cssfilters mediaqueries no-regions classlist datalistelem details texttrackapi track filereader filesystem fullscreen getusermedia gamepads xhr2 quotamanagement performance raf no-stylescoped websocketsbinary no-webintents todataurljpeg todataurlwebp webp translated-ltr" style=""><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <meta charset="utf-8">
  <meta property="twitter:account_id" content="1593210261">
  <title>Usando CORS - HTML5 Rocks</title>
  <meta property="og:type" content="article">
  <body data-href="tutorials-cors" onload="" class="article tutorial">



		<p align="center" style="font-size: 20px;">
		<a href="http://www.html5rocks.com/en/tutorials/cors/#" onclick="makeCorsRequest(); return false;"><font><font class="">Muestra Ejecutar</font></font></a>
		</p>


		<script>

	   window.isCompatible = function() {
			  
				var xhr = new XMLHttpRequest();
				if ("withCredentials" in xhr) {
				return true;
				} else if (typeof XDomainRequest != "undefined") {
				return true;
				}
				return false;

		};

		if (isCompatible() === false) {
		        document.getElementById('notcompatible').className = '';
		}
		
		
		function createCORSRequest(method, url) {
		  var xhr = new XMLHttpRequest();
		  if ("withCredentials" in xhr) {
			// XHR for Chrome/Firefox/Opera/Safari.
			xhr.open(method, url, true);
		  } else if (typeof XDomainRequest != "undefined") {
			// XDomainRequest for IE.
			xhr = new XDomainRequest();
			xhr.open(method, url);
		  } else {
			// CORS not supported.
			xhr = null;
		  }
		  return xhr;
		}

		// Helper method to parse the title tag from the response.
		function getTitle(text) {
		  return text.match('<title>(.*)?</title>')[1];
		}

		// Make the actual CORS request.
		function makeCorsRequest() {
			  // All HTML5 Rocks properties support CORS.
			//  var url = 'http://updates.html5rocks.com';
			  var url = 'http://owl-group.org/xrh.php';

			  var xhr = createCORSRequest('GET', url);
			  if (!xhr) {
				alert('CORS not supported');
				return;
		      }

		  // Response handlers.
		  xhr.onload = function() {
			var text = xhr.responseText;
			//var title = getTitle(text);
			var title = text;
			alert('Response from CORS request to ' + url + ': ' + title);
		  };

		  xhr.onerror = function() {
			alert('Woops, there was an error making the request.');
		  };

//    xhr.onreadystatechange = handler ; 
		  xhr.send();
		}
		
		</script>

			  </div>
			</section>
		  </article>
		  
		  </div>

	



		</body></html>